package top.kaoshanji.p1ch05f.main;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import top.kaoshanji.p1ch05f.config.ProjectConfig;
import top.kaoshanji.p1ch05f.services.CommentService;
import top.kaoshanji.p1ch05f.services.UserService;

/**
 * 代码清单-p1ch05f-103页a：测试Spring在Main类中注入原型bean的行为
 * @author kaoshanji
 * ^_^
 * create time 2025/4/27 21:03
 */
public class Main {

    public static void main(String[] args) {

        var context = new AnnotationConfigApplicationContext(ProjectConfig.class);

        // 这两个bean都是单例bean，都依赖一个相同的原型bean
        var s1 = context.getBean(CommentService.class);
        var s2 = context.getBean(UserService.class);

        // 被依赖的对象是不同的
        System.out.println(s1.getCommentRepository() == s2.getCommentRepository());

    }

}
